package logic

import (
	"context"
	"teacher1/teacherrpc/teacherrpc"

	"teacher1/api/internal/svc"
	"teacher1/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type TeacherUpdatePwdLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewTeacherUpdatePwdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TeacherUpdatePwdLogic {
	return &TeacherUpdatePwdLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *TeacherUpdatePwdLogic) TeacherUpdatePwd(req *types.TeacherUpdatePwdRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	if req.Password != req.NewPassword {
		return &types.Response{
			Msg:  "两次输入的密码不一致,请重新输入",
			Code: 500,
			Data: nil,
		}, nil
	}
	pwd, err := l.svcCtx.TeacherRpc.TeacherUpdatePwd(l.ctx, &teacherrpc.TeacherUpdatePwdRequest{
		Password:    req.Password,
		NewPassword: req.Password,
		TeacherId:   req.TeaCherId,
	})
	if err != nil {
		return &types.Response{
			Msg:  "修改失败",
			Code: 500,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "修改成功",
		Code: 200,
		Data: pwd,
	}, nil
}
